"""
魔术方法：__call__ ---> 可调用对象
"""
import json
from json.encoder import JSONEncoder


class Person:

    def __init__(self, name, age):
        self.name = name
        self.age = age

    def __call__(self, *args, **kwargs):
        self.watch_av()

    def watch_av(self):
        if self.age < 18:
            print(f'{self.name}只能看《熊出没》')
        else:
            print(f'{self.name}可以观看成人片')


class PersonJsonEncoder(JSONEncoder):

    def default(self, o):
        return {
            'name': o.name,
            'age': o.age
        }


person = Person('王大锤', 15)
# person.watch_av()
# person()
print(json.dumps(person, cls=PersonJsonEncoder))
